package com.wjs.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wjs.dao.CategoryMapper;
import com.wjs.entity.Category;
import com.wjs.entity.Tea;
import com.wjs.service.CategoryService;
import com.wjs.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class CategoryServiceImpl implements CategoryService {
    SqlSession session= MybatisUtils.getSession();
    CategoryMapper cm=session.getMapper(CategoryMapper.class);

    @Override
    public List<Category> selectAll() {
        return cm.selectAll();
    }

    @Override
    public PageInfo<Category> selectAllByPage(int curPage,int pageSize) {
        //告知要其分页了，设置分页信息，第一页和一页查三条
        PageHelper.startPage(curPage,pageSize);
        //获取查询全部的集合
        List<Category>list=cm.selectAll();
        //将集合封装
        PageInfo<Category> pi= new PageInfo<>(list);
        return pi;
    }

    @Override
    public void deleteByID(int id) {
        cm.deleteByID(id);
        session.commit();
    }

    @Override
    public void addCategory(Category category) {
        cm.addCategory(category);
        session.commit();
    }
}
